package com.mm.controller.web.taxi;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.AopLog;
import com.mm.base.annotation.VerifyToken;
import com.mm.util.result.DPage;
import com.mm.util.result.DResult;
import com.mm.domain.taxi.DCarInfo;
import com.mm.serivce.taxi.IDCarInfoService;
import com.mm.vo.mp.PayOrderReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 车辆信息表 前端控制器
 * </p>
 *
 * @author JueDream
 * @since 2021-08-13
 */
@Api(value = "/car/v1", tags = {"车辆信息"})
@Slf4j
@VerifyToken
@RestController
@RequestMapping("/car/v1")
@AopLog(type = "车辆信息", stackTraceOnErr = true)
public class DCarInfoController {

    private final IDCarInfoService carInfoService;

    public DCarInfoController(IDCarInfoService carInfoService) {
        this.carInfoService = carInfoService;
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", dataTypeClass = Integer.class, name = "page", value = ""),
            @ApiImplicitParam(paramType = "query", dataType = "int", dataTypeClass = Integer.class, name = "limit", value = ""),
            @ApiImplicitParam(paramType = "query", dataType = "string", dataTypeClass = String.class, name = "carText", value = "")
    })
    @ApiOperation(value = "车辆列表查询接口", notes = "", httpMethod = "POST")
    @PostMapping("/queryCarPage")
    public DResult queryCarPage(@RequestParam int page, @RequestParam int limit, @RequestParam(required = false) String carText) {
        Page<DCarInfo> carInfoPage = carInfoService.queryCarPage(page, limit, carText);
        DPage<DCarInfo> carInfoDPage = DPage.to(carInfoPage);
        return DResult.of(carInfoDPage);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", dataTypeClass = Integer.class, name = "carId", value = "")
    })
    @ApiOperation(value = "车辆列表查询单个接口", notes = "", httpMethod = "POST")
    @PostMapping("/queryCarOne")
    public DResult queryCarOne(@RequestParam Integer carId) {
        return DResult.of(carInfoService.queryCarOne(carId));
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "DCarInfo", dataTypeClass = DCarInfo.class, name = "carInfo", value = "")
    })
    @ApiOperation(value = "车辆列表编辑接口", notes = "", httpMethod = "POST")
    @Transactional
    @PostMapping("/saveOrUpdate")
    public DResult saveOrUpdate(@RequestBody DCarInfo carInfo) {
        boolean flag = false;
        if (carInfo.getCarId() < 0) {
            // 新增
            flag = carInfoService.save(carInfo);
        } else if (carInfo.getCarId() > 0) {
            // 更新
            flag = carInfoService.updateById(carInfo);
        }
        return DResult.of(flag);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", dataTypeClass = Integer.class, name = "carId", value = "")
    })
    @ApiOperation(value = "车辆删除接口", notes = "", httpMethod = "DELETE")
    @DeleteMapping("/delete")
    public DResult delete(@RequestParam Integer carId) {
        boolean flag = false;
        if (carId > 0) {
            flag = carInfoService.removeCar(carId);
        }
        return DResult.of(flag);
    }

}
